#include <wiringPi.h>

#define A_pin 0    //定义PWM引脚 GPIO.0
#define B_pin 1    //定义PWM引脚 GPIO.1
#define C_pin 2    //定义PWM引脚 GPIO.2
#define D_pin 3    //定义PWM引脚 GPIO.3
#define E_pin 4    //定义PWM引脚 GPIO.4
#define F_pin 5    //定义PWM引脚 GPIO.5
#define G_pin 6    //定义PWM引脚 GPIO.6
#define DP_pin 7    //定义PWM引脚 GPIO.7

#define D1_pin 29    //定义PWM引脚 GPIO.29
#define D2_pin 28    //定义PWM引脚 GPIO.28
#define D3_pin 27    //定义PWM引脚 GPIO.27
#define D4_pin 26    //定义PWM引脚 GPIO.26

void initGpio(){
    // 设置段位为输出
    pinMode (A_pin, OUTPUT);
    pinMode (B_pin, OUTPUT);
    pinMode (C_pin, OUTPUT);
    pinMode (D_pin, OUTPUT);
    pinMode (E_pin, OUTPUT);
    pinMode (F_pin, OUTPUT);
    pinMode (G_pin, OUTPUT);
    pinMode (DP_pin, OUTPUT);
    // 延时 20ms
    delay(20);
    // 段位输出高
    digitalWrite (A_pin, HIGH);
    digitalWrite (B_pin, HIGH);
    digitalWrite (C_pin, HIGH);
    digitalWrite (D_pin, HIGH);
    digitalWrite (E_pin, HIGH);
    digitalWrite (F_pin, HIGH);
    digitalWrite (G_pin, HIGH);
    digitalWrite (DP_pin, HIGH);

    // 位选
    pinMode (D1_pin, OUTPUT);
    pinMode (D2_pin, OUTPUT);
    pinMode (D3_pin, OUTPUT);
    pinMode (D4_pin, OUTPUT);
    // 位选 输出高
    digitalWrite (D1_pin, LOW);
    digitalWrite (D2_pin, LOW);
    digitalWrite (D3_pin, LOW);
    digitalWrite (D4_pin, HIGH);
}

void setSeg(int wei,int duan){
    if(wei == 0){
        digitalWrite (D1_pin, LOW);
        digitalWrite (D4_pin, HIGH);
    }else{
        digitalWrite (D4_pin, HIGH);
        digitalWrite (D1_pin, LOW);
    }
    digitalWrite (A_pin, LOW);
}

int main (void)
{
    wiringPiSetup ();               // wiringPi库初始化
    initGpio();
    setSeg(0,0);
  return 0 ;
} 